﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.Utils;
using Aij1.BLL;
using Aij1.Cms;
using Aij1.Model;
using DevExpress.Xpo;

namespace Aij1
{
    /// <summary>
    /// 客户留言页面
    /// </summary>
    public partial class GuestBook : BasePage
    {
        protected WebPager WPager;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                Submit();
            }
            R.DataSource = AlbumData.GetPagedAlbumsList(WPager);
            R.DataBind();
            PageName = "留言本";

            Keywords = "来客留言";
            Description = "请在此留言,用QQ号登录后才能留言";
        }

        void Submit()
        {
            G_GuestBook gb = new G_GuestBook(XpoSession)
            {
                Content = Request.Form["Content"],
                GuestName = CurrentCustomer.SysName,
                QQ = CurrentCustomer.QQ,
                Tel = CurrentCustomer.Tel,
                WriteTime = DateTime.Now,
            };

            gb.Content = gb.Content.Replace("<", "&lt;").Replace(">", "&gt;");
            if (gb.Content.Length > 500)
            {
                ClientScript.RegisterClientScriptBlock(typeof(GuestBook), "alert",
           "alert('留言太长了，请限制在500字以内。')", true);
                return;
            }

            try
            {
                gb.Save();

                ClientScript.RegisterClientScriptBlock(typeof(GuestBook), "alert",
                "alert('谢谢你的参与！\\r\\n您的留言已经提交成功！管理员会在一个工作日内给您回复！')", true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void Page_init(object sender, EventArgs e)
        {
            //CNM.CategoryId = catId;
            //CNM.CategoryType = typeof(A_Category);

            WPager = new WebPagerSEO()
            {
                KeyId = "Oid",
                OrderBy = "Oid DESC",
                Query = "SELECT * FROM G_GuestBook WHERE GCRecord IS NULL",
                PageSize = 20,
            };
        }
    }
}
